package main

import (
	"fmt"
	"helloword01/31chatroom/client/process"
	commonmodel "helloword01/31chatroom/common/model"
	"os"
)

func main() {
	printMenu()
}

func printMenu() {
	var key int
	for {
		fmt.Println("-------------------------欢迎登录多人聊天系统-------------------------")
		fmt.Println("\t\t\t 1 登录聊天室")
		fmt.Println("\t\t\t 2 注册用户")
		fmt.Println("\t\t\t 3 退出系统")
		fmt.Println("\t\t\t 请选择(1~3):")
		fmt.Scanf("%d \n", &key)
		switch key {
		case 1:
			loginMenu()
		case 2:
			register()
		case 3:
			logoutMenu()
			os.Exit(0)
		default:
			fmt.Println(commonmodel.InputError)
		}

	}
}

// loginMenu
//
//	@Description:
func loginMenu() {
	var userId int
	var userPwd string
	fmt.Println("登录聊天室：")
	fmt.Println("请输入用户ID：")
	fmt.Scanf("%d \n", &userId)
	fmt.Println("请输入用户密码：")
	fmt.Scanf("%s \n", &userPwd)
	up := &process.UserProcess{}
	err := up.Login(userId, userPwd)
	if err != nil {
		fmt.Println(err.Error())
	}
}

// register
//
//	@Description:
func register() {
	var userId int
	var userPwd string
	var userName string
	fmt.Println("请输入用户ID：")
	fmt.Scanf("%d \n", &userId)
	fmt.Println("请输入用户密码：")
	fmt.Scanf("%s \n", &userPwd)
	fmt.Println("请输入用户名：")
	fmt.Scanf("%s \n", &userName)
	up := &process.UserProcess{}
	err := up.Register(userId, userPwd, userName)
	if err != nil {
		fmt.Println(err.Error())
	}
}

func logoutMenu() {
	fmt.Println("退出成功")
}
